package com.peng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.peng.pojo.Grade;
import com.peng.service.GradeService;
import com.peng.utils.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sms/gradeController")
public class GradeController {
    @Autowired
    private GradeService gradeService;

    @GetMapping("/getGrades/{pageNo}/{pageSize}")
    public Result getGrades(@PathVariable("pageNo") Integer pageNo,@PathVariable("pageSize") Integer pageSize,String gradeName){
        IPage<Grade> iPage=gradeService.getGrades(pageNo,pageSize,gradeName);
        return Result.ok(iPage);
    }
    @PostMapping("/saveOrUpdateGrade")
    public Result saveOrUpdateGrade(@RequestBody Grade grade){
        gradeService.saveOrUpdate(grade);
        return Result.ok();
    }

    @ApiOperation("删除grade对象")
    @DeleteMapping("/deleteGrade")
    public Result deleteGrade(@ApiParam("传入的grade对象") @RequestBody List<Integer> list){
        gradeService.removeByIds(list);
        return Result.ok();
    }

    @GetMapping("/getGrades")
    public Result getGrades(){
        List<Grade> list = gradeService.list();

        return Result.ok(list);
    }
}
